package com.sf.fy.uav.common.utils;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;


/**
 * check token
 *
 * @author 01430312
 */
@Component
public class CheckTokenUtil {
    @Value("${check.token.url:http://uocs-cs-ie-uocs-core-apis.intsit.sfcloud.local}")
    private String checkTokenUrl;
    @Autowired
    private RestTemplate restTemplate;

    public void checkToken(String token) {


        ResponseEntity<String> responseEntity = restTemplate.getForEntity(checkTokenUrl + "/apis-auth/login/check_token?token=" + token, String.class);
        String body = responseEntity.getBody();
        if (!JSONObject.parseObject(body).getBoolean("success")) {
            throw new RuntimeException(JSONObject.parseObject(body).getString("errorMessage"));
        }
    }
}
